package com.qys.livesMall.common.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.*;
import java.util.Date;

/**
 * @packageName:
 * @className:LocalDateTimeToTimestampSerializer
 * @Description:
 * @author:guomx
 * @date:2023/6/309:58
 */
public class LocalDateToTimestampSerializer extends JsonSerializer<LocalDate> {

    @Override
    public void serialize(LocalDate value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        ZonedDateTime zonedDateTime = value.atStartOfDay(ZoneId.systemDefault());
        Date date = Date.from(zonedDateTime.toInstant());
        jsonGenerator.writeNumber(date.getTime());
    }
}

